package com.lcq.springbootcreate.project.Util;

import com.lcq.springbootcreate.project.common.Constant;
import org.apache.tomcat.util.codec.binary.Base64;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/*
 * MD5工具
 * */
public class MD5Utils {
    public static String getMD5str(String strValue) throws NoSuchAlgorithmException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        return Base64.encodeBase64String(md5.digest((strValue + Constant.SALT).getBytes()));
    }

    // 测试生成对md5的数
    public static void main(String[] args) {
        try {
            String password = "12345";
            String passwordMD5 = MD5Utils.getMD5str(password + Constant.SALT);
            System.out.println(passwordMD5);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }
}
